home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17892 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.voyager.net!news
  2. From: David Wade <dwade@vixa.voyager.net>
  3. Newsgroups: comp.lang.c++
  4. Subject: File I/O using fwrite()
  5. Date: Wed, 17 Apr 1996 20:31:44 -0400
  6. Organization: The Game Room
  7. Message-ID: <31758D70.1D38@vixa.voyager.net>
  8. NNTP-Posting-Host: lans234.dial.voyager.net
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.01 (Win95; I)
  13.  
  14. HELP!!!  I am having a major problem getting random access file routines 
  15. to work properly.  For some reason, no matter what I do the information 
  16. is always written at the end of the file instead of where I want it to 
  17. replace...  All I need to do is update a record in a potentailly large 
  18. file, and I can't load the entire file and re-write it to do it.  If 
  19. anyone sees what I am doing wrong, or has a possible solution using 
  20. other means, I would greatly appreciate the info.  The funtion looks 
  21. like this:
  22.  
  23.         f=_fsopen(".\\data\\weapons.dat", "ab+", SH_DENYNONE);
  24.         if(f == NULL)
  25.         {
  26.                 printf("ERROR!");
  27.                 exit(1);
  28.         };
  29.         rewind(f);
  30.         fseek(f,(item_data.reference-1)*sizeof(item_struct),SEEK_SET);
  31.         fwrite(&item_data, sizeof(item_struct), 1, f);
  32.         fclose(f);
  33.  
  34.  
  35. The struct is of type item_struct, and item_data is an instance of that 
  36. struct.
  37.  
  38. If anyone can help, I would greatly appreciate it.  Thanks
  39.  
  40. Mark Roberts
  41.